package com.weifeng.learneasyexcel.readexceldemo;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class WriteExcelDemo1 {
    public static void main(String[] args) {
//        readexceldemo1();
//        String fileName = "/Users/wumingyang/Desktop/JAVA项目/http-client-demo/excel/07版.xlsx";
        String fileName = "C:\\Users\\Administrator\\Desktop\\07版.xlsx";
        write(fileName);
    }
    public static void readexceldemo1(){

//        String fileName = "C:\\Users\\Administrator\\Desktop\\文件1.xlsx";
        String fileName = "/Users/wumingyang/Desktop/JAVA项目/http-client-demo/excel/07版.xlsx";
        List<Exceluntity> objects = EasyExcel.read(fileName).head(Exceluntity.class).sheet().doReadSync();
        System.out.println(objects);
        for (Exceluntity list : objects){
            System.out.println(JSON.toJSONString(list));
        }


    }
    public static List<Exceluntity> date(){
        List<Exceluntity> arrayList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Exceluntity e = new Exceluntity();
            e.setBiaoti("标题"+i);
            e.setRiqi(new Date());
            e.setShuzi(123.0);
            arrayList.add(e);
        }
        return arrayList;
    }


    public static void  write(String fileName){


//        EasyExcel.write(fileName, exceluntity.class).sheet("第一个sheet").doWrite(date());

        ExcelWriter build = EasyExcel.write(fileName, Exceluntity.class).build();
        WriteSheet diyigesheet = EasyExcel.writerSheet("diyigesheet").build();
        build.write(date(),diyigesheet);
        build.close();


    }
}
